cmake build system: visiblity support for clang
[supercollider.git] / Help / UGens / Synth control / IndexInBetween.html
blob2ced0c6c4d637e3370b2e0b64322c0e24bebe8e6
1 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
2 <html>
3 <head>
4 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
5 <meta http-equiv="Content-Style-Type" content="text/css">
6 <title></title>
7 <meta name="Generator" content="Cocoa HTML Writer">
8 <meta name="CocoaVersion" content="824.48">
9 <style type="text/css">
10 p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Helvetica}
11 p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px}
12 p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica}
13 p.p4 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #000000; min-height: 16.0px}
14 p.p5 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #000000; min-height: 12.0px}
15 p.p6 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #000000}
16 p.p7 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #bf0000}
17 span.s1 {color: #0000ff}
18 span.s2 {color: #0000bf}
19 span.Apple-tab-span {white-space:pre}
20 </style>
21 </head>
22 <body>
23 <p class="p1"><b>IndexInBetween<span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></b></p>
24 <p class="p2"><br></p>
25 <p class="p3"><b>IndexInBetween.ar(bufnum, in, mul, add)</b></p>
26 <p class="p3"><b>IndexInBetween.kr(bufnum, in, mul, add)</b></p>
27 <p class="p2"><br></p>
28 <p class="p3">Finds the (lowest) point in the <a href="../../ServerArchitecture/Buffer.html"><span class="s1">Buffer</span></a> at which the input signal lies in-between the two values, and returns the index. The fractional part of the index is suitable for linearly interpolating between the buffer slot values.<span class="Apple-converted-space"> </span></p>
29 <p class="p2"><br></p>
30 <p class="p3">For example, if the Buffer contains [3, 21, 25, 26] and the input has the value 22, then the output will be 1.25, because the value 22 is in-between the values stored in indices 1 and 2 and in fact is one-quarter of the way along the interval between them.</p>
31 <p class="p2"><br></p>
32 <p class="p3">IndexInBetween is the complement of <a href="IndexL.html"><span class="s1">IndexL</span></a>.</p>
33 <p class="p2"><br></p>
34 <p class="p3"><b>bufnum</b> - index of the buffer</p>
35 <p class="p3"><b>in</b> - the input signal.</p>
36 <p class="p4"><br></p>
37 <p class="p4"><br></p>
38 <p class="p5"><br></p>
39 <p class="p6">(</p>
40 <p class="p7">// autotune.</p>
41 <p class="p6">s = <span class="s2">Server</span>.local;</p>
42 <p class="p6">t = ([0, 1, 3, 4, 7, 11, 12] + 70).midicps;</p>
43 <p class="p6">b = <span class="s2">Buffer</span>(s, t.size, 1);</p>
44 <p class="p5"><br></p>
45 <p class="p7">// alloc and set the values</p>
46 <p class="p6">s.listSendMsg( b.allocMsg( b.setnMsg(0, t) ).postln );</p>
47 <p class="p5"><br></p>
48 <p class="p6">{</p>
49 <p class="p6"><span class="Apple-tab-span"> </span><span class="s2">var</span> index, in, out, f0, fdiff;</p>
50 <p class="p6"><span class="Apple-tab-span"> </span><span class="s2">var</span> bufnum = b;</p>
51 <p class="p6"><span class="Apple-tab-span"> </span>in = <span class="s2">Pulse</span>.ar(<span class="s2">MouseX</span>.kr(t.minItem, t.maxItem)) * 0.1;</p>
52 <p class="p6"><span class="Apple-tab-span"> </span>f0 = <span class="s2">Pitch</span>.kr(in).at(0);</p>
53 <p class="p6"><span class="Apple-tab-span"> </span>index = <span class="s2">IndexInBetween</span>.kr(bufnum, f0);</p>
54 <p class="p6"><span class="Apple-tab-span"> </span>fdiff = index.frac * (<span class="s2">Index</span>.kr(bufnum, index + 1) - <span class="s2">Index</span>.kr(bufnum, index));</p>
55 <p class="p6"><span class="Apple-tab-span"> </span>out = <span class="s2">PitchShift</span>.ar(in, 0.1, 1 - (fdiff / f0), 0.01, 0.01);</p>
56 <p class="p6"><span class="Apple-tab-span"> </span><span class="s2">RLPF</span>.ar(out, [2000, 5000], 0.3)</p>
57 <p class="p6">}.play;</p>
58 <p class="p6">)</p>
59 <p class="p5"><br></p>
60 <p class="p6">b.free;</p>
61 <p class="p5"><br></p>
62 <p class="p5"><br></p>
63 <p class="p7">// basic test.</p>
64 <p class="p6">(</p>
65 <p class="p5"><br></p>
66 <p class="p6">s = <span class="s2">Server</span>.local;</p>
67 <p class="p6">t = [ 200, 210, 400, 430, 600, 800 ];</p>
68 <p class="p6">b = <span class="s2">Buffer</span>(s, t.size, 1);</p>
69 <p class="p5"><br></p>
70 <p class="p7">// alloc and set the values</p>
71 <p class="p6">s.listSendMsg( b.allocMsg( b.setnMsg(0, t) ).postln );</p>
72 <p class="p5"><br></p>
73 <p class="p5"><br></p>
74 <p class="p6">{</p>
75 <p class="p6"><span class="Apple-tab-span"> </span><span class="s2">var</span> index, f0, f1, f3;</p>
76 <p class="p6"><span class="Apple-tab-span"> </span><span class="s2">var</span> bufnum = b;</p>
77 <p class="p6"><span class="Apple-tab-span"> </span>f0 = <span class="s2">MouseX</span>.kr(200, 900);</p>
78 <p class="p6"><span class="Apple-tab-span"> </span>index = <span class="s2">IndexInBetween</span>.kr(bufnum, f0);</p>
79 <p class="p6"><span class="Apple-tab-span"> </span>f1 = <span class="s2">IndexL</span>.kr(bufnum, index);</p>
80 <p class="p6"><span class="Apple-tab-span"> </span><span class="s2">SinOsc</span>.ar([f0, f1]) * 0.1</p>
81 <p class="p5"><span class="Apple-tab-span"> </span></p>
82 <p class="p6">}.play;</p>
83 <p class="p6">)</p>
84 <p class="p5"><br></p>
85 <p class="p6">b.free;</p>
86 <p class="p5"><br></p>
87 <p class="p5"><br></p>
88 <p class="p7">// One way to map across from an arbitrary piecewise curve, onto another:</p>
89 <p class="p7">// We use IndexInBetween to "unmap" your input into integer slots,<span class="Apple-converted-space"> </span></p>
90 <p class="p7">// and then use IndexL to do the reverse, to "map" onto your other distribution.<span class="Apple-converted-space"> </span></p>
91 <p class="p7">// This example maps a sort-of-exponential curve onto a sort-of-sinusoidal curve:</p>
92 <p class="p5"><br></p>
93 <p class="p6">~from = [1, 2, 4, 8, 16];</p>
94 <p class="p6">~to <span class="Apple-converted-space">  </span>= [0, 1,<span class="Apple-converted-space">  </span>0,<span class="Apple-converted-space">  </span>-1,<span class="Apple-converted-space">    </span>0];</p>
95 <p class="p6">(</p>
96 <p class="p6">x={</p>
97 <p class="p6"><span class="Apple-tab-span"> </span><span class="s2">IndexL</span>.kr(~to.as(<span class="s2">LocalBuf</span>), <span class="s2">IndexInBetween</span>.kr(~from.as(<span class="s2">LocalBuf</span>),<span class="s2">MouseX</span>.kr(~from.first,~from.last).poll).poll).poll</p>
98 <p class="p6">}.play</p>
99 <p class="p6">)</p>
100 </body>
101 </html>